home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / gfx / 3d / fixobj12.lha / FixObj.e < prev   
Text File  |  1993-03-20  |  2KB  |  86 lines

  1. /* FixObj.e    Replaces $0d characters out of Pixel3D Pro
  2.            Wavefront files with $20
  3.            Also swaps the signs of Z coords, so the objects will
  4.          look the same as they did in Imagine and P3D Pro
  5.            Also checks if file has already been operated on
  6.                                   */
  7.  
  8. ENUM ER_NONE, ER_FILE, ER_MEM, ER_USAGE,ER_BRK, ER_OUT, ER_FIXED
  9.  
  10. DEF flen, mem:PTR TO CHAR,wmem:PTR TO CHAR, pos:PTR TO CHAR,wpos:PTR TO CHAR
  11. DEF handle=NIL,corrections=0,vertices=0,faces=0
  12.  
  13. PROC main()
  14.    WriteF('FixObj 1.2 : Fixes Pixel3DPro-generated Wavefront files\n')
  15.    WriteF('(c) 1993 Danimal\n\n')
  16.    IF StrCmp(arg,'',1) OR StrCmp(arg,'?',2) THEN error(ER_USAGE)
  17.    flen:=FileLength(arg)
  18.    handle:=Open(arg,OLDFILE)
  19.    IF (flen<1) OR (handle=NIL) THEN error(ER_FILE)
  20.    mem:=New(flen); wmem:= New(flen+(flen/4))
  21.    IF (mem=NIL OR wmem=NIL) THEN error(ER_MEM)
  22.    IF Read(handle,mem,flen)<>flen THEN error(ER_FILE)
  23.    Close(handle); handle:=NIL
  24.    WriteF('Now fixing "\s"\n',arg)
  25.    fix()
  26.    IF corrections=0 THEN error(ER_FIXED)
  27.    handle:=Open(arg,NEWFILE)
  28.    IF handle=NIL THEN error(ER_OUT)
  29.    WriteF('Writing "\s".\n',arg)
  30.    IF Write(handle,wmem,flen)<>flen THEN error(ER_OUT)
  31.    error(ER_NONE)
  32. ENDPROC
  33.  
  34. PROC error(nr)
  35.    IF handle THEN Close(handle)
  36.    SELECT nr
  37.       CASE ER_NONE;   WriteF('Vertices & Sign Changes: \d, Faces: \d\n',vertices,faces)
  38.               WriteF('Done.\n')
  39.       CASE ER_FILE;   WriteF('Could not read file "\s"\n',arg)
  40.       CASE ER_MEM;    WriteF('No memory for loading file\n')
  41.       CASE ER_USAGE;  WriteF('USAGE: Wavefix <file>\n')
  42.       CASE ER_BRK;    WriteF('**User Break**\n')
  43.       CASE ER_OUT;    WriteF('Could not write file "\s"\n',arg)
  44.       CASE ER_FIXED;  WriteF('File "\s" appears to be already fixed.\n',arg)
  45.    ENDSELECT
  46.    CleanUp(0)
  47. ENDPROC
  48.  
  49. PROC fix()
  50. /*     This procedure makes the actual corrections to the file   */
  51.  
  52. DEF counter=0,vertex=FALSE
  53.    pos:=mem; wpos:=wmem
  54.  
  55.    REPEAT
  56.       IF CtrlC() THEN error(ER_BRK)
  57.  
  58.       IF pos[]=$76 THEN vertex:=TRUE
  59.       IF pos[]=$0D
  60.      pos[]:=$20
  61.      corrections++
  62.      IF vertex
  63.         REPEAT
  64.            pos[]--; wpos[]--
  65.         UNTIL pos[]=$09; pos[]++; wpos[]++
  66.         IF pos[]=$2d
  67.            pos[]:=$20
  68.         ELSE
  69.            wpos[]++:=$2d; flen++
  70.         ENDIF
  71.         vertex:=FALSE
  72.         vertices++
  73.      ELSE
  74.         faces++
  75.      ENDIF
  76.  
  77.       ENDIF
  78.       IF pos[]=$0a
  79.      counter++
  80.       ENDIF
  81.       wpos[]++:=pos[]++
  82.       IF Mod(counter,50)=0 THEN WriteF('\bLine: \d   ',counter)
  83.    UNTIL (pos-mem)>=flen
  84.    WriteF('\n')
  85. ENDPROC
  86.